package com.xzc.java8.B_Stream.f_flatmap;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

public class FlatMapTest {

    public static void main(String[] args) {
        //fail map输出的是2个String数组，distinct也是针对2个数组进行
        List<String> words = Arrays.asList("Hello", "World");
        List<String[]> abc = words.stream().map(word -> word.split("")).distinct().collect(toList());
        System.out.println(abc);

        //fail 后面一个map输出是2个String流，distinc也是针对这2个流进行
        List<Stream<String>> abc1 = words.stream().map(word -> word.split("")).map(Arrays::stream).distinct().collect(toList());
        System.out.println(abc1);

        //flat 将2个流合并成一个流
        List<String> abc2 = words.stream().map(w -> w.split("")).flatMap(Arrays::stream).distinct().collect(toList());
        System.out.println(abc2);
    }
}
